<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<style>
			div{
				width:100px;
				height:100px;
				background: #000;
				float: left;
				margin-left:30px;
			}
		</style>
	</head>

	<body>
		<button>点击变颜色</button>
		<div></div>
		<div></div>
		<div></div>
	</body>
<script>
	var but=document.getElementsByTagName('button')[0]
	var div=document.getElementsByTagName("div")
	but.onclick=function(){
		for(var i=0; i<div.length; i++){
			div[i].style.background="red"
		}
	}
</script>
</html>
